#include "WPILib.h"
#include "SmartJoypad.h"

SmartJoypad::SmartJoypad(UINT32 port)
{
	joystick = new Joystick(port);
	
	for (int i = 0; i < NUM_BUTTONS; ++i)
			buttons[i] = false;
	
	for (int i = 0; i < NUM_AXES; ++i)
		axes[i] = 0;
}

SmartJoypad::~SmartJoypad()
{
	delete joystick;
}

bool SmartJoypad::GetButton(JoypadButton button)
{
	return joystick->GetRawButton(button);
}

bool SmartJoypad::GetButtonPress(JoypadButton button)
{
	return !buttons[button - 1] && joystick->GetRawButton(button);
}

bool SmartJoypad::GetButtonRelease(JoypadButton button)
{
	return buttons[button - 1] && !joystick->GetRawButton(button);
}

float SmartJoypad::GetAxis(JoypadAxis axis)
{
	return joystick->GetRawAxis(axis);
}

float SmartJoypad::GetAxisDelta(JoypadAxis axis)
{
	return joystick->GetRawAxis(axis) - axes[axis - 1];
}

void SmartJoypad::Remember()
{
	for (int i = 1; i <= NUM_BUTTONS; ++i)
		buttons[i - 1] = joystick->GetRawButton(i);
	
	for (int i = 1; i <= NUM_AXES; ++i)
		axes[i - 1] = joystick->GetRawAxis(i);
}
